// diagnose_paths.js - 诊断路径问题
const path = require('path');
const fs = require('fs');

console.log("当前工作目录:", process.cwd());
console.log("__dirname:", __dirname);
console.log("process.execPath:", process.execPath);

// 检查向量存储路径
const vectorStorePath = path.join(__dirname, 'vector_store');
console.log("计算出的向量存储路径:", vectorStorePath);

// 检查路径是否存在
console.log("向量存储路径是否存在:", fs.existsSync(vectorStorePath));

if (fs.existsSync(vectorStorePath)) {
    const files = fs.readdirSync(vectorStorePath);
    console.log("向量存储目录中的文件:", files);
    
    // 检查具体文件
    const indexPath = path.join(vectorStorePath, 'hnswlib.index');
    console.log("hnswlib.index 路径:", indexPath);
    console.log("hnswlib.index 是否存在:", fs.existsSync(indexPath));
    
    if (fs.existsSync(indexPath)) {
        const stats = fs.statSync(indexPath);
        console.log("hnswlib.index 文件大小:", stats.size, "字节");
    }
} else {
    console.log("尝试列出父目录内容:");
    const parentDir = path.join(__dirname, '..');
    if (fs.existsSync(parentDir)) {
        const parentFiles = fs.readdirSync(parentDir);
        console.log("父目录中的文件/目录:", parentFiles);
    }
}